
Page({
    data: {
        
        tab_idx: 1,            //  tab切换 0商品详情            
        integral: 4600,        //  拥有的积分    
        userInfo: {},          //  用户名/电话/地址   
        result: false,          //  是否显示弹窗
        hasAward: false,       //  抽奖是否中奖
        isLottery: false,      //  t 点击的是抽奖  f点击的是兑换

        swiper:[
            { src: "../../img/public/advertising.png" },
            { src: "../../img/public/advertising.png" },
            { src: "../../img/public/advertising.png" },
        ],
        conver_Info:{
            l_integral:100,
            c_integral: 4600,
        }
    },

    tab:function(e){
        const {tip} = e.target.dataset;
        this.setData({ tab_idx: tip})
    },
    // 积分抽奖
    lottery:function(){
        const that = this;
        const { integral, conver_Info } = this.data;
        const msg = '确定使用' + conver_Info.l_integral + '积分进行抽奖';


        if (integral >= conver_Info.l_integral) {
            // 请求数据
            wx.showModal({
                title: '提示',
                content: msg,
                success: function (res) {
                    if (res.confirm) {
                        console.log("积分抽奖")
                        that.setData({ isLottery: true, result: true })
                    } else if (res.cancel) {

                    }
                }
            })
        };
        
    },
    // 积分兑换
    conversion: function () {
        const that = this;
        const { integral, conver_Info}=this.data;
        const title = '确定使用' + conver_Info.c_integral +'积分兑换?';

        if (integral >= conver_Info.c_integral){
            wx.showModal({
                title: title,
                content: '兑换成功可在兑换记录查看',
                success: function (res) {
                    if (res.confirm) {
                        that.setData({ isLottery:false, result:true})
                    } else if (res.cancel) {
                       
                    }
                }
            })
        };
    },
    // 关闭弹层dialog Close 
    Close:function(){
        this.setData({ result: false })
    },
    // 填写收货信息
    fillInfo:function(){
        const that = this;
        wx.chooseAddress({
            success: function (res) {
                let address = res.provinceName + res.cityName + res.countyName + ',' + res.detailInfo;
                let userInfo={
                    name: res.userName,
                    postalCode: res.postalCode,
                    address: address,
                    tel: res.telNumber
                };
                that.setData({
                    userInfo: userInfo
                })
            }
        })
    },
    // 领奖
    getAward:function(){
        // 发起请请求
        //.....

        this.Close();
        this.setData({ userInfo:{}}); //清空地址信息
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
    
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
    
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
    
    }
})